package com.oss.controller.oss;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oss.common.BaseResponse;
import com.oss.dto.oss.student.*;
import com.oss.entity.oss.Student;
import com.oss.service.oss.StudentService;
import com.oss.vo.oss.student.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 学员管理
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    StudentService studentService;

    /**
     * 自动生成一个为一个手机号
     * @return
     */
    @PostMapping("/createPhone")
    public BaseResponse<String> createPhone(){
        return BaseResponse.success((Object)studentService.createPhone());
    };

    @PostMapping("/getAll")
    public BaseResponse<List<Student>> getAll(){
        return BaseResponse.success(studentService.getAll());
    }

    /**
     * 根据合约代码, 获取学员信息(获取持有相关合约的学员)
     * @param dto
     * @return
     */
    @PostMapping("/getByInstrumentCode")
    public BaseResponse<List<GetByInstrumentCodeStudentVO>> getByInstrumentCode(@RequestBody ListByInstrumentCodeDto dto){
        return BaseResponse.success(studentService.getByInstrumentCode(dto));
    }
    @PostMapping("/selectByPage")
    public BaseResponse<IPage<StudentPageVO>> selectByPage(@RequestBody @Valid StudentPageDto dto){
        return BaseResponse.success(studentService.selectByPage(dto));
    }
    @PostMapping("/export")
    public void export(@RequestBody @Valid StudentPageDto dto) throws Exception {
        studentService.export(dto);
    }

    @PostMapping("/getByID")
    public BaseResponse<StudentDetailInfoVO> getByID(@RequestBody @Valid StudentGetByIDDto dto){
        return BaseResponse.success(studentService.getDetailById(dto.getId()));
    }

    /**
     * web端个人信息主页
     * @param dto
     * @return
     */
    @PostMapping("/getByPhone")
    public BaseResponse<StudentInfoVO> getByPhone(@RequestBody @Valid StudentGetByPhoneDto dto){
        return BaseResponse.success(studentService.getByPhone(dto));
    }
    @PostMapping("/add")
    public BaseResponse<String> add(@RequestBody @Valid StudentAddDto dto){
        return studentService.add(dto);
    }

    /**
     * 网页端注册
     * @param dto
     * @return
     */
    @PostMapping("/webRegister")
    public BaseResponse<String> webRegister(@RequestBody @Valid StudentAddDto dto){
        return studentService.add(dto);
    }
    @PostMapping("/update")
    public BaseResponse<String> update(@RequestBody @Valid StudentUpdateDto dto){
        return studentService.updateData(dto);
    }
    @PostMapping("/delete")
    public BaseResponse<String> delete(@RequestBody @Valid StudentGetByIDDto dto){
        return BaseResponse.success(studentService.delete(dto));
    }

    /**
     * 合并学员信息
     * @param dto
     * @return
     */
    @PostMapping("/mergeStudent")
    public BaseResponse<String> mergeStudent(@RequestBody @Valid StudentMergeDto dto){
        return BaseResponse.success(studentService.mergeStudent(dto));
    }
}